package com.zzz.system.service.user.impl;

import com.github.pagehelper.PageHelper;
import com.zzz.common.core.enums.ResultCode;
import com.zzz.common.security.exception.ServiceException;
import com.zzz.system.domain.user.User;
import com.zzz.system.domain.user.dto.UserDTO;
import com.zzz.system.domain.user.dto.UserQueryDTO;
import com.zzz.system.domain.user.vo.UserVO;
import com.zzz.system.mapper.user.UserMapper;
import com.zzz.system.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: oj-project
 * @BelongsPackage: com.zzz.system.service.user.impl
 * @Author: zhai
 * @CreateTime: 2025-10-19  19:36
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * @description: 获取c端用户列表
     * @author: zhai
     * @date: 2025/10/19 23:12
     * @param: [userQueryDTO]
     * @return: java.util.List<com.zzz.system.domain.user.vo.UserVO>
     **/
    @Override
    public List<UserVO> list(UserQueryDTO userQueryDTO) {
        PageHelper.startPage(userQueryDTO.getPageNum(), userQueryDTO.getPageSize());
        List<UserVO> questionVOList = userMapper.selectUserList(userQueryDTO);
        return questionVOList;
    }

    /**
     * @description: 跟新用户状态
     * @author: zhai
     * @date: 2025/10/23 07:54
     * @param: [userDTO]
     * @return: int
     **/
    @Override
    public int updateStatus(UserDTO userDTO) {
        User user = userMapper.selectById(userDTO.getUserId());
        if (user == null) {
            throw new ServiceException(ResultCode.FAILED_USER_NOT_EXISTS);
        }
        user.setStatus(userDTO.getStatus());
        return userMapper.updateById(user);
    }
}
